// pages/my/my.js
var app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        UserInfo: {},
        currentNavs: { name: "我的", list: app.globalData.navs },
        isChinese: false,
        orderCount: 0,
        ticketCount: 0,
        user: {},
        newCount: 0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onShow() {
        wx.removeTabBarBadge({
            index: 1
        })
        app.globalData.newCount = 0
        this.setData({
            newCount: 0
        })
        if (getApp().getApi.session == null || getApp().getApi.session == "") {
            getApp().watch = this.initData
        } else {
            this.initData()
        }
        this.setData({
            isChinese: wx.getStorageSync("isChinese")
        })
    },
    initData() {
        var that = this

        wx.getUserInfo({
            success: function(res) {
                var userInfo = res.userInfo
                var nickName = userInfo.nickName
                var avatarUrl = userInfo.avatarUrl
                var gender = userInfo.gender //性别 0：未知、1：男、2：女
                var province = userInfo.province
                var city = userInfo.city
                var country = userInfo.country
                that.setData({
                    UserInfo: res.userInfo,
                    avatarUrl: userInfo.avatarUrl
                })
            }
        })

        app.getApi.getProducts("POST", { method: "opg.orderHeadAndValidTicketCount.get", unionId: app.globalData.unionId }).then(data => {
            that.setData({
                orderCount: data.data.orderCount,
                ticketCount: data.data.ticketCount,
                user: app.globalData.union
            })
        })
    },
    order() {
        wx.navigateTo({
            url: '../order/order',
            success: function(res) {},
            fail: function(res) {},
            complete: function(res) {},
        })
    },
    ticket() {
        wx.navigateTo({
            url: '../ticket/ticket',
            success: function(res) {},
            fail: function(res) {},
            complete: function(res) {},
        })
    },
    language() {
        wx.navigateTo({
            url: '../language/language',
            success: function(res) {},
            fail: function(res) {},
            complete: function(res) {},
        })
    },
    onPullDownRefresh: function() {
        this.onLoad()
        wx.stopPullDownRefresh()
    },
})